import math

##########################################################################
#Thank you for considering this program as a finalist.  The strategy behind this program
# is that of a hypocrite.  That is, it maintains a good public reputation while secretly 
# engaging in selfish strategems behind the public's back.  I assumed that since it has worked
# so well for politicians that it would also work in the context of this game.
#Being a hypocrite is also a successful strategy in nature, in the form of Batesian mimicry.  
#One species will evolve the physical characteristics of a dangerous organism and enjoy being avoided by 
#predators, as in the viceroy butterfly mimicking the poisonous monarch butterfly.

# My hypocritical strategy was to pretend to be a cooperator, and enjoy a good reputation, while
# secretly sabotaging my fellow cooperators.  I start by calculating an ideal reputation.  If
# I were to cooperate with other cooperators, what would my reputation be?
# I then make sure to maintain my reputation with the appropriate number of hunts.  
# The hypocritical twist is that I do not actually cooperate with the other cooperators.  
# I slack against them, while hunting with the slackers.  Why would it be beneficial to do this?
# If I slack against a hunter I earn +1 food, and if I hunt against a slacker I lose -3 food.
# This equals out to -2 food.  
# What if I had been honest and cooperated with the hunters and slacked against the slackers?
# I would earn 0 from the hunter, and -2 from the slacker.  
# -2 = -2, so these two strategies are equal.  However, I am benefiting by being a hypocrite in two ways: 
# One is that I am hurting the other cooperators, moving me ahead.  The second is that
# some of the slackers may actually hunt with me because of my reputation.  In that scenario
# I would get +1 from the cooperating hunter that I slacked against, and then 0 from the slacker that decided to 
# hunt with me.  Part of my strategy is to pick out the slackers most likely to hunt with me 
# on occasion, so I will hunt against the slackers with the best reputations.

# My code does not consider the existence of the m values for the following reason:
# My goal is to edge ahead of the other hunters, and while long-term survival would be 
# rewarded in the real world, this particular game does not value group survival 
# over extinction.  Additionally, since the m rewards go to slackers and hunters alike, there was no
# incentive to hunt against my personal best interest.

# This program begins by hunting against every individual in the first round.  The losses incurred 
# in that round are compensated for in subsequent rounds based on the program's great reputation.
# This program, though, is only able to act as a hypocrite if there are slackers to cover his tracks.
# When the game evolves to a situation in which all the players are hunting 100% of the time, 
# then the hypocrite has no choice but to hunt along with them.  If he were to try to slack against 
# them, his reputation would go down and he would be ostracized from the group.
# The hypocrite can only hope that once the game develops into a cooperative truce, enough
# gains have been made at the expense of the other hunters to ensure first place.

def hunt_choices(round_number, current_food, current_reputation, m,  player_reputations):

    	global totalPlayers
	global idealReputation
	global totalIdealHunts

	if(round_number == 1):
		totalPlayers = 0.00
		idealReputation = 0.00
		totalIdealHunts = 0.00
	else:
		idealReputation = totalIdealHunts/totalPlayers #calculated reps for the last round


	NumberofPlayersThisRound = len(player_reputations)
	totalPlayers = totalPlayers + NumberofPlayersThisRound


	hunt_decisions = list()
	slackerList = list()
	hunterList = list()

	slackersThisRound = 0
	huntsThisRound = 0

	
	for i in range (0, len(player_reputations)):

		if (player_reputations[i] >= idealReputation):
			totalIdealHunts += 1
			huntsThisRound += 1

	slackersThisRound = NumberofPlayersThisRound - huntsThisRound

	
	slackerCounter = slackersThisRound
	hunterCounter = huntsThisRound

# IDENTIFY THE BEST SLACKERS and BEST HUNTERS
	if (huntsThisRound > 0 and slackersThisRound > 0):
		
		for i in range (0, len(player_reputations)):
			if (player_reputations[i] < idealReputation): #the idealReputation is what a cooperator would have
				hunt_decisions.append('s')
				slackerList.append(player_reputations[i])
			else: 
				hunt_decisions.append('h')
				hunterList.append(player_reputations[i])

		slackerList.sort() #this puts it in ascending order
		hunterList.sort()

		slackerEnd = len(slackerList) - 1
		hunterEnd = len(hunterList) - 1 #I use this to pick out the best hunters to betray

		

# THE HYPOCRITE STRATEGY
		while (hunterCounter > 0 or slackerCounter > 0):
	
			for i in range (0, len(player_reputations)):
				if (hunt_decisions[i] == 'h' and slackerCounter > 0): #If they have a good rep, betray them
					if(player_reputations[i] == hunterList[hunterEnd]):
						hunt_decisions[i] = 's'
						slackerCounter -= 1
						hunterEnd -= 1
					elif (hunterEnd < 0):
						slackerCounter = 0		
				elif (hunt_decisions[i] == 's' and hunterCounter > 0): #If they have a bad rep, hunt with them
					if(player_reputations[i] == slackerList[slackerEnd]):
						hunt_decisions[i] = 'h'
						hunterCounter -= 1 #Make sure to have enough hunts to maintain a good rep
						slackerEnd -= 1			
					elif (slackerEnd < 0):
						hunterCounter = 0
						
		return hunt_decisions;
		
#########################################################
#If there are no more slackers remaining
	else:
		for i in range (0, len(player_reputations)):
			
			if (player_reputations[i] >= current_reputation):		
				decision = 'h'
	
			else: 
				decision = 's'
			hunt_decisions.append(decision)
			
		if (NumberofPlayersThisRound == 1): # if there is only one person left, slack against them
			del hunt_decisions[0:len(hunt_decisions)]
			decision = 's'
			hunt_decisions.append(decision)
	
		return hunt_decisions;

def hunt_outcomes(food_earnings): 

    pass 
    

def round_end(award, m, number_hunters):
    
    pass


















